'\" te
.\" Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH USB_PIPE_DRAIN_REQS 9F "Jan 5, 2004"
.SH NAME
usb_pipe_drain_reqs \- Allow completion of pending pipe requests
.SH SYNOPSIS
.nf
#include <sys/usb/usba.h>



\fBint\fR \fBusb_pipe_drain_reqs\fR(\fBdev_info_t *\fR\fIdip\fR, \fBusb_pipe_handle_t\fR \fIpipe_handle\fR,
     \fBuint_t\fR \fItimeout\fR, \fBusb_flags_t\fR \fIusb_flags\fR,
     \fBvoid (*\fR\fIcallback\fR)(usb_pipe_handle_t \fIpipe_handle\fR,
     \fBusb_opaque_t\fR \fIcallback_arg\fR, \fBint\fR \fIrval\fR, \fBusb_cb_flags_t\fR \fIflags)\fR,
     \fBusb_opaque_t\fR \fIcallback_arg\fR);
.fi

.SH INTERFACE LEVEL
illumos DDI specific (illumos DDI)
.SH PARAMETERS
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 16n
Pointer to the device's \fBdev_info\fR structure.
.RE

.sp
.ne 2
.na
\fB\fIpipe_handle\fR\fR
.ad
.RS 16n
Handle of the pipe containing pending requests.
.RE

.sp
.ne 2
.na
\fB\fItimeout\fR\fR
.ad
.RS 16n
Maximum wait time for requests to drain. Must be a non-negative value in
seconds. Zero specifies no timeout.
.RE

.sp
.ne 2
.na
\fB\fIflags\fR\fR
.ad
.RS 16n
USB_FLAGS_SLEEP is the only flag recognized. Wait for completion and do not
call callback.
.RE

.sp
.ne 2
.na
\fB\fIcallback\fR\fR
.ad
.RS 16n
Callback handler to notify of asynchronous completion.
.RE

.sp
.ne 2
.na
\fB\fIcallback_arg\fR\fR
.ad
.RS 16n
Second argument passed to callback function.
.RE

.SH DESCRIPTION
The \fBusb_pipe_drain_reqs()\fR function provides waits for pending requests to
complete and then provides synchronous or asynchronous notification that all
pending requests on a non-shared pipe indicated by pipe_handle have completed.
For a shared pipe (such as the default control pipe used by multiple drivers
each managing one interface of a device), this function provides notification
that all pending requests on that pipe that are associated with a given dip are
completed.
.sp
.LP
The \fBusb_pipe_drain_reqs()\fR function can be used to notify a close
procedure when the default control pipe is clear during device closure, thereby
allowing the close procedure to continue safely. Normally, a synchronous call
to \fBusb_pipe_close\fR(9F) allows all requests in a pipe to finish before
returning. However, a client driver cannot close the default control pipe.
.sp
.LP
If USB_FLAGS_SLEEP is set in flags, block until all pending requests are
completed. Otherwise, return immediately and call the callback handler when all
pending requests are completed.
.sp
.LP
The \fIcallback\fR parameter accepts the asynchronous callback handler, which
takes the following arguments:
.sp
.ne 2
.na
\fBusb_pipe_handle_t default_pipe_handle\fR
.ad
.sp .6
.RS 4n
Handle of the pipe to drain.
.RE

.sp
.ne 2
.na
\fBusb_opaque_t callback_arg\fR
.ad
.sp .6
.RS 4n
callback_arg specified to \fBusb_pipe_drain_reqs()\fR.
.RE

.sp
.ne 2
.na
\fBint rval\fR
.ad
.sp .6
.RS 4n
Request status.
.RE

.sp
.ne 2
.na
\fBusb_cb_flags_t callback_flags\fR
.ad
.sp .6
.RS 4n
Status of the queueing operation. Can be:
.sp
.ne 2
.na
\fBUSB_CB_NO_INFO\fR
.ad
.RS 27n
Callback was uneventful.
.RE

.sp
.ne 2
.na
\fBUSB_CB_ASYNC_REQ_FAILED\fR
.ad
.RS 27n
Error starting asynchronous request.
.RE

.RE

.SH RETURN VALUES
.ne 2
.na
\fBUSB_SUCCESS\fR
.ad
.RS 23n
Request is successful.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_ARGS\fR
.ad
.RS 23n
\fIdip\fR argument is \fBNULL\fR. USB_FLAGS_SLEEP is clear and callback is
\fBNULL\fR.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_CONTEXT\fR
.ad
.RS 23n
Called from callback context with the USB_FLAGS_SLEEP flag set.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_PIPE\fR
.ad
.RS 23n
Pipe is not open, is closing or is closed.
.RE

.SH CONTEXT
May be called from user or kernel context.
.sp
.LP
If the USB_CB_ASYNC_REQ_FAILED bit is clear in usb_cb_flags_t, the callback, if
supplied, can block because it is executing in kernel context. Otherwise the
callback cannot block. Please see \fBusb_callback_flags\fR(9S) for more
information on callbacks.
.SH EXAMPLES
.in +2
.nf
  mydev_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
 {

      ...
      ...

      mydev_state->pipe_state = CLOSED;

      /* Wait for pending requests of a pipe to finish.  Don't timeout. */
      (void) usb_pipe_drain_reqs(
          dip, pipe_handle, 0, USB_FLAGS_SLEEP, NULL, 0);

      /*
       * Dismantle streams and tear down this instance,
       * now that all requests have been sent.
       */
      qprocsoff(q);
      ...
      ...
      ddi_remove_minor_node(dip, NULL);
      ...
      ...
 }

.fi
.in -2

.SH NOTES
For pipes other than the default control pipe, it is recommended to close the
pipe using a synchronous \fBusb_pipe_close()\fR. \fBusb_pipe_close()\fR with
the USB_FLAGS_SLEEP flag allows any pending requests in that pipe to complete
before returning.
.sp
.LP
Do not call \fBusb_pipe_drain_reqs()\fR while additional requests are being
submitted by a different thread. This action can stall the calling thread of
\fBusb_pipe_drain_reqs()\fR unnecessarily.
.SH ATTRIBUTES
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Architecture	PCI-based systems
_
Interface stability	Committed
.TE

.SH SEE ALSO
.BR attributes (7),
.BR usb_pipe_close (9F),
.BR usb_pipe_reset (9F),
.BR usb_callback_flags (9S)
